﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using DSS_XNA.Engine.Primitives;
using Game.Engine.World.Worlds.RPGWorld;

namespace DSS_XNA.Engine.World.Worlds.RPGWorld
{
    public class TileAnimation
    {
        #region Properties

        public List<Tile> Tiles
        {
            get { return _tiles; }
            set { _tiles = value; }
        }
        private List<Tile> _tiles = new List<Tile>();

        #endregion

        #region Public Methods

        public TileAnimation()
        {
        }

        public bool Render(SpriteBatch spriteBatch, Rectangle destRect, TileSetManager tileSetManager, TileProperties tileProperties)
        {
            if(this.Tiles.Count <= 0)
                return false;

            // just  use the first tile for now - animate them later
            // NOTE: Only the first tile in the anim will contain the special properties like IsCollidable!
            Tile tile = this.Tiles[0];

            Texture2D tileSet = tileSetManager.TileSets[tile.TileSetIdx].Texture;

            if (tileProperties.IsCollidable)
                spriteBatch.Draw(tileSet, destRect, tile.SourceRect, Color.Red);
            else
                spriteBatch.Draw(tileSet, destRect, tile.SourceRect, Color.White);

            return true;
        }

        public static bool operator==(TileAnimation a1, TileAnimation a2)
        {
            if(a1.Tiles.Count != a2.Tiles.Count)
                return false;

            for(int i = 0; i < a1.Tiles.Count; i++)
            {
                if(a1.Tiles[i] != a2.Tiles[i])
                    return false;
            }

            return true;
        }

        public static bool operator !=(TileAnimation a1, TileAnimation a2)
        {
            return !(a1 == a2);
        }

        #endregion
    }
}
